<template>
    <view class="content">
		<view v-if="dashboards && dashboards.length > 0">
			<view v-for="(menuItem, menuIndex) in dashboards" :key="menuIndex">
			    <!-- <view class="padding listTitle">
			        {{ menuItem.name }}
			    </view> -->
			    <view class="part flexRow">
			        <menu-entry
			            v-for="(item, index) in menuItem.children"
			            :key="index"
						:menu="item"
						@toMenu="toMenu">
			        </menu-entry>
			    </view>
			</view>
		</view>
        <view class="no-data" v-else>
        	<text>{{$t('app.homepage.noApplication')}}</text>
        </view>
    </view>
</template>

<script>
import { getAppResource } from '@/api/platform/common.js'
import { utilities, business } from '@/utils/common.js'

export default {
    data() {
        return {
			idKey: 'id',
			parentIdKey: 'parentId',
			childrenKey: 'children',
			dashboards: [],
			backButtonPress: 0
        }
    },
    onLoad() {
		this.init()
	},
	onShow() {
		business.refreshMsgCount()
	},
    methods: {
		init() {
			// 过滤目录为‘应用’的菜单
			this.dashboards = uni.getStorageSync("menuList").filter(item => {
				return item.alias == 'yy'
			})
			// // 运检管理
			// let opInsList = menuList[0].children.filter(item => {
			// 	return item.alias != 'wzgl'
			// })
			// let opInsMenu = {
			// 	alias: 'yjgl',
			// 	name: '运检管理',
			// 	children: opInsList
			// }
			// // 物资管理
			// let materialList = menuList[0].children.filter(item => {
			// 	return item.alias == 'wzgl'
			// })
			// let materialMenu = {
			// 	alias: 'wzgl',
			// 	name: '物资管理',
			// 	children: materialList[0].children
			// }
			// this.dashboards = [
			// 	opInsMenu,
			// 	materialMenu
			// ]
		},
		toMenu(menu) {
			if(menu.alias == 'wzgl') {
				uni.navigateTo({
				    url: '/pages/business/material/index/index'
				})
			}
			if (menu.defaultUrl) {
			    uni.navigateTo({
			        url: menu.defaultUrl
			    })
			}
		}
	},
	onBackPress() {
		this.backButtonPress++;
		if (this.backButtonPress > 1) { 
			// 退出清除角标
			plus.runtime.setBadgeNumber(0);
			// 退出清除token
			uni.removeStorageSync('_app_token');
			plus.runtime.quit();
		} else {
			plus.nativeUI.toast(this.$t('app.message.pressAgainExit'));
		}
		return true;
	}
}
</script>

<style lang="scss">
	page {
		background: #f1f2f4;
	}
	
	.content {
		margin-bottom: 50px;
		background-color: #fff;
	}
	
	.listTitle {
		font-size: 15px;
		font-weight: bolder;
		padding: 0 10px;
		padding-top: 10px;
		color: #999;
	}
	
	.flexRow {
	  display: flex;
	  flex-direction: row;
	  flex-wrap: wrap;
	  justify-content: flex-start;
	  align-items: center;
	  padding: 10px 0;
	}
	
	.no-data {
		display: flex;
		min-height: 150px;
		background-color: #FFFFFF;
		justify-content: center;
		align-items: center;
		text-align: center;
		font-size: 14px;
		color: #353535;
	}
</style>
